package com.gouwudai.gobbs.service.impl;

import java.util.List;

import org.extremecomponents.table.limit.Limit;

import com.gouwudai.gobbs.common.Constants;
import com.gouwudai.gobbs.common.IPageList;
import com.gouwudai.gobbs.dao.IAfficheDAO;
import com.gouwudai.gobbs.pojo.TbbsAffiche;
import com.gouwudai.gobbs.service.IAfficheService;
import com.litt.core.exception.DBException;
import com.litt.core.util.ExtremeTableUtil;
import com.litt.core.util.ParamUtils;

public class AfficheServiceImpl implements IAfficheService
{
	IAfficheDAO afficheDAO;
	
	public void save(TbbsAffiche tbbsAffiche)
	{	
		afficheDAO.save(tbbsAffiche);
	}

	public TbbsAffiche load(Integer id)
	{
		return (TbbsAffiche)afficheDAO.load(id);
	}

	public void update(TbbsAffiche tbbsAffiche)
	{
			afficheDAO.update(tbbsAffiche);
	}

	public void delete(Integer Id)
	{
			afficheDAO.delete(Id);
	}
	
	/**
	 * 删除多个
	 * @param Ids
	 * @return
	 */
	public void delete(String Ids)
	{
			afficheDAO.delete(Ids);
	}
	
    /**
     * 查询当前分类/版面的公告信息，前8项
     * @param classId
     * @return
     * @throws DBException
     */
    public List listByClassId(Integer classId)
    {
    	return afficheDAO.listByClassId(classId);
    }

	public List list(int pageIndex,int pageSize)
	{
		return afficheDAO.list(pageIndex, pageSize);
	}
	
	public IPageList listPage(int pageIndex,int pageSize,String sort)
	{
		return afficheDAO.listPage(pageIndex, pageSize,sort);
	}
	
	public void AutoBindingTable(javax.servlet.http.HttpServletRequest request)
	{
		Limit limit = ExtremeTableUtil.getLimit(request, Constants.DEFAULT_PAGE_SIZE);
        IPageList page = this.listPage(limit.getPage(), limit.getCurrentRowsDisplayed(),ExtremeTableUtil.getSort(limit));
		request.setAttribute("resultList",page.getRsList());
		request.setAttribute("totalRows",page.getTotalSize());
	}
	
	public void listByPage(javax.servlet.http.HttpServletRequest request)
	{
		int classId = ParamUtils.getIntParameter(request, "classId");		
		Limit limit = ExtremeTableUtil.getLimit(request, Constants.DEFAULT_PAGE_SIZE);
        IPageList page = afficheDAO.listPageByClassId(classId,limit.getPage(), limit.getCurrentRowsDisplayed(),ExtremeTableUtil.getSort(limit));
		request.setAttribute("resultList",page.getRsList());
		request.setAttribute("totalRows",page.getTotalSize());
	}

	public void setAfficheDAO(IAfficheDAO afficheDAO) {
		this.afficheDAO = afficheDAO;
	}
	
}